﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLogic;

namespace BusinessLogic
{
    [Serializable()]
    public class ServiceTotalList : System.Collections.CollectionBase
    {
        public ServiceTotal this[int index]
        {
            get { return (ServiceTotal)this.List[index]; }
            set { this.List[index] = value; }
        }

        public int IndexOf(ServiceTotal item)
        {
            return base.List.IndexOf(item);
        }

        public int Add(ServiceTotal item)
        {
            return this.List.Add(item);
        }

        public void Remove(ServiceTotal item)
        {
            this.InnerList.Remove(item);
        }
        
        public void CopyTo(Array array, int index)
        {
            this.List.CopyTo(array, index);
        }
        
        public void AddRange(ServiceTotalList collection)
        {
            for (int i = 0; i < collection.Count; i++)
            {
                this.List.Add(collection[i]);
            }
        }

        public void AddRange(ServiceTotal[] collection)
        {
            this.AddRange(collection);
        }

        public bool Contains(ServiceTotal item)
        {
            return this.List.Contains(item);
        }

        public void Insert(int index, ServiceTotal item)
        {
            this.List.Insert(index, item);
        }

        public string CreateXMLString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<SERVICETOTALS>");

            int sequence = 0;

            foreach (ServiceTotal st in this.List)
            {
                sb.Append("<ITEM>");
                sb.AppendFormat("<ID>{0}</ID>", st.ID);
                sb.AppendFormat("<DATE>{0}</DATE>", st.Date);
                sb.AppendFormat("<LABOR>{0}</LABOR>", st.Labor);
                sb.AppendFormat("<MILEAGE>{0}</MILEAGE>", st.Mileage);
                sb.AppendFormat("<OTHER>{0}</OTHER>", st.Other);
                sb.AppendFormat("<TRAVEL>{0}</TRAVEL>", st.Travel);
                sb.AppendFormat("<OTHERDESCRIPTION>{0}</OTHERDESCRIPTION>", st.OtherDescription);
                sb.AppendFormat("<SEQUENCE>{0}</SEQUENCE>", sequence++);
                sb.Append("</ITEM>");
            }

            return sb.Append("</SERVICETOTALS>").ToString();
        }

        public void Fill(Guid serviceReportID)
        {
            this.AddRange(ServiceTotalListDataAccess.GetServiceReportTotalList(serviceReportID));
        }
    }
}